package com.gopay.cashier.web.controller;

import java.util.Date;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gopay.cashier.service.SmsAcService;
import com.gopay.cashier.service.SmsSupportService;
import com.gopay.common.exception.GopayException;
import com.gopay.sms.common.constants.SMSAppId;
import com.gopay.sms.common.constants.SMSResCode;
import com.gopay.sms.common.domain.RequestVO;
import com.gopay.sms.common.domain.ResponseVO;

/**
 * 短信认证 2016/08/22
 * 
 * @author ssj
 *
 */
@Controller
public class CustSmsAcController extends BaseController {
	/**
	 * 短信认证接口
	 */
	@Resource(name = "smsAcService")
	private SmsAcService smsAcService;

	/**
	 * 校验管理员当前状态
	 * 
	 * @param bankPhoneNo
	 * @return
	 */
	@RequestMapping("/smsAc/sendSMSaC.shtml")
	@ResponseBody
	public Map<String, String> sendSMSaC() {
		Map<String, String> resMap = smsAcService.getMapSmsAc(getLoginUser());
		return resMap;
	}

	/**
	 * @Description: 短信认证服务 发送指定业务短信
	 * @author msi
	 */
	@RequestMapping(value = "/smsAc/sendBizSMS")
	@ResponseBody
	public ResponseVO sendBizMSM() throws GopayException {
		ResponseVO response = null;
		// 判断用户次数 用户状态
		if (smsAcService.canSendSms(getLoginUser())) {
			RequestVO req = new RequestVO();// 不做次数限制
			Map<String, String> resMap = smsAcService.getMapSmsAc(getLoginUser());
			req.setMobile(resMap.get("custMob"));
			req.setUserId(getLoginUser().getUser().getUserId());
			req.setAppId(SMSAppId._10074.value);// 自定义短信
			response = smsAcService.sendBizSMSAc(req, getLoginUser().getUser().getUserId());
			if (SMSResCode.SMS_DEND_SUCCESS.value.equals(response.getStatusCode())) {
				// 若发送成功则设置 短信提示
				response.setMessage(smsAcService.getMsmSendTIps(resMap.get("custMob")));
			}
		} else {
			response = new ResponseVO();
			response = smsAcService.getSmsLockedTips(getLoginUser(), response);// 构建锁定提示
		}
		return response;
	}

}
